package com.okaixz.manager.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.okaixz.common.annotation.Log;
import com.okaixz.common.core.controller.BaseController;
import com.okaixz.common.core.domain.AjaxResult;
import com.okaixz.common.enums.BusinessType;
import com.okaixz.manager.article.domain.CArticle;
import com.okaixz.manager.article.service.ICArticleService;
import com.okaixz.common.utils.poi.ExcelUtil;
import com.okaixz.common.core.page.TableDataInfo;

/**
 * AI写作案例Controller
 * 
 * @author ruoyi
 * @date 2024-08-18
 */
@RestController
@RequestMapping("/manager/article")
@Api("文章管理")
public class CArticleController extends BaseController
{
    @Autowired
    private ICArticleService cArticleService;

    /**
     * 查询AI写作案例列表
     */
    @PreAuthorize("@ss.hasPermi('manager:article:list')")
    @GetMapping("/list")
    @ApiOperation("获取文章列表")
    public TableDataInfo list(CArticle cArticle)
    {
        startPage();
        List<CArticle> list = cArticleService.selectCArticleList(cArticle);
        return getDataTable(list);
    }

    /**
     * 导出AI写作案例列表
     */
    @PreAuthorize("@ss.hasPermi('manager:article:export')")
    @Log(title = "AI写作案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CArticle cArticle)
    {
        List<CArticle> list = cArticleService.selectCArticleList(cArticle);
        ExcelUtil<CArticle> util = new ExcelUtil<CArticle>(CArticle.class);
        util.exportExcel(response, list, "AI写作案例数据");
    }

    /**
     * 获取AI写作案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cArticleService.selectCArticleById(id));
    }

    /**
     * 新增AI写作案例
     */
    @PreAuthorize("@ss.hasPermi('manager:article:add')")
    @Log(title = "AI写作案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CArticle cArticle)
    {
        return toAjax(cArticleService.insertCArticle(cArticle));
    }

    /**
     * 修改AI写作案例
     */
    @PreAuthorize("@ss.hasPermi('manager:article:edit')")
    @Log(title = "AI写作案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CArticle cArticle)
    {
        return toAjax(cArticleService.updateCArticle(cArticle));
    }

    /**
     * 删除AI写作案例
     */
    @PreAuthorize("@ss.hasPermi('manager:article:remove')")
    @Log(title = "AI写作案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cArticleService.deleteCArticleByIds(ids));
    }
}
